/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import mensch.Player;
import org.apache.log4j.Logger;

/**
 *
 * @author robert
 */
@ManagedBean(name = "registeredPlayers")
@ApplicationScoped
public class RegisteredPlayers implements Serializable {

    private final static Logger LOG = Logger.getLogger(RegisteredPlayers.class.getName());
    Map<String, Player> registered = new HashMap<String, Player>();

    /*
     * Adds a player to the registered Players
     */
    public boolean addPlayer(Player p) {
        if (!registered.containsKey(p.getUsername())) {
            registered.put(p.getUsername(), p);
            LOG.info("Groesse der Hashmap: " + registered.size());
            return true;
        }
        return false;
    }

    public List getRegisteredPlayers() {
        return new ArrayList<Player>(registered.values());
    }

    public Player getRegisteredPlayer(String username) {
        LOG.info("Suche nach dem Usernamen: " + username + " in der Hashmap");
        return registered.get(username);
    }
}
